#include <bits/stdc++.h>
// 2025/02/09
// tag:
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, m, floyd[101][101];

signed main()
{
    cin >> n >> m;
    memset(floyd, 0x3f, sizeof(floyd));
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        floyd[x][y] = 1;
    }
    for (int i = 1; i <= n; i++)
        floyd[i][i] = 0;

    for (int k = 1; k <= n; k++) 
        for (int i = 1; i <= n; i++) 
            for (int j = 1; j <= n; j++) 
                floyd[i][j] = min(floyd[i][j], floyd[i][k] + floyd[k][j]);
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        bool flag = true;
        for (int j = 1; j <= n; j++) {
            if (floyd[i][j] == 0x3f3f3f3f && floyd[j][i] == 0x3f3f3f3f) {
                flag = false;
                break;
            }
        }
        if (flag)
            ans++;
    }
    cout << ans << endl;
    return 0;
}